package com.yzh.book.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {

    @RequestMapping("/login")
    public String login(String userName, String password1, HttpSession session) {
        //1校验参数 2校验验证码 3返回结果
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password1)) {
            return "用户名或者密码为空";
        }
        if (!"admin".equals(userName) || !"admin".equals(password1)) {
            System.out.printf(userName + " + " + password1);
            return "密码错误";
        }
        //正确情况
        session.setAttribute("userName", userName);
        return "芝麻开门~";
    }
}
